/* eslint-disable camelcase */
import request from '../service/axios';

export function getTenantAccessToken() {
  return request({
    method: 'get',
    url: '/open-apis/auth/v3/tenant_access_token/internal',
    params: {
      app_id: 'cli_a1e7b63227b9900e',
      app_secret: 'EeJWWP8SyKAjwvXt8xMjSgRVMe2FgmQD',
    }
  });
}

// 获取魔法师时间线
export function getFeishuMagicTimeline() {
  return new Promise((resolve: any) => {
    getTenantAccessToken().then((res: any) => {
      resolve(request({
        method: 'get',
        url: '/open-apis/bitable/v1/apps/bascnwMAd625UPNCRHIuaBcCgOf/tables/tblyT3TBM6Zmg0IT/records',
        headers: {
          Authorization: 'Bearer ' + res.tenant_access_token,
        },
      }));
    });
  }) as unknown as Promise<{
    data: {
      has_more: boolean;
      items: any[];
      page_token: string;
      total: number;
    }
  }>;
}

// 获取魔法列表
export function getFeishuMagicList() {
  return new Promise((resolve: any) => {
    getTenantAccessToken().then((res: any) => {
      resolve(request({
        method: 'get',
        url: '/open-apis/bitable/v1/apps/bascnwMAd625UPNCRHIuaBcCgOf/tables/tblrzIGBgYOUnfT5/records',
        headers: {
          Authorization: 'Bearer ' + res.tenant_access_token,
        },
      }));
    });
  }) as unknown as Promise<{
    data: {
      has_more: boolean;
      items: {
        key: string;
        level: string;
        class: string;
        value: string;
      }[];
      page_token: string;
      total: number;
    }
  }>;
}

// 获取飞书魔法师修炼进度
export function getFeishuMagicAdvance() {
  return new Promise((resolve: any) => {
    getTenantAccessToken().then((res: any) => {
      resolve(request({
        method: 'get',
        url: '/open-apis/bitable/v1/apps/bascnwMAd625UPNCRHIuaBcCgOf/tables/tblBXxY4AmjwLZaV/records',
        headers: {
          Authorization: 'Bearer ' + res.tenant_access_token,
        },
      }));
    });
  }) as unknown as Promise<{
    data: {
      has_more: boolean;
      items: {
        key: string;
        level: string;
        class: string;
        value: string;
      }[];
      page_token: string;
      total: number;
    }
  }>;
}
